package com.xiaoshuidi.cloud.module.member.controller.app.comment;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.security.core.util.SecurityFrameworkUtils;
import com.xiaoshuidi.cloud.module.member.controller.app.comment.vo.AppMemberListVO;
import com.xiaoshuidi.cloud.module.member.controller.app.comment.vo.MemberCommentCreateVO;
import com.xiaoshuidi.cloud.module.member.controller.app.comment.vo.MemberCommentRespVO;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.comment.MemberCommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import java.util.List;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;


@Tag(name = "租客APP - 评论中心")
@RestController
@RequestMapping(ApiConstants.NAME+"/comment")
@Validated
@Slf4j
public class AppCommentController {
@Resource
private MemberCommentService memberCommentService;

    @PostMapping("/create")
    @Operation(summary = "新增评论")
    public CommonResult<Boolean> create(@RequestBody MemberCommentCreateVO vo) {
        return success(memberCommentService.create(vo));
    }


    @GetMapping("/get-by-id/{id}")
    @Operation(summary = "查询评论详情")
    public CommonResult<MemberCommentRespVO> getById(@PathVariable("id") Long id) {
        return success(memberCommentService.getById(id));
    }

    @GetMapping("/get-by-message-id/{id}")
    @Operation(summary = "查询评论详情")
    public CommonResult<MemberCommentRespVO> getByMessageId(@PathVariable("id") Long id) {
        return success(memberCommentService.getByMessageId(id));
    }


    @GetMapping("/get-list-by-user-id/{status}")
    @Operation(summary = "根据用户id查询用户评论列表")
    public CommonResult<List<AppMemberListVO>> getListByUserId(@PathVariable("status") Boolean status) {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        log.info("===获取的会员id:userId{},status:{}",userId,status);
        return success(memberCommentService.getListByUserId(userId,status));
    }

}
